package com.sbl.bajw.pc.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sbl.bajw.common.web.JsonResultUtil;
import com.sbl.bajw.common.web.RequestUnit;
import com.sbl.bajw.pc.model.buildingModel;
import com.sbl.bajw.pc.service.buildingModelService;
import com.sbl.bajw.util.JsonUtil;

@Controller
@RequestMapping("/buildingModel")
public class buildingModelAction {

	@Resource
	private buildingModelService service;
	
	@RequestMapping(value = "/getModel")
	public ModelAndView getModel(HttpServletRequest request, HttpServletResponse response){
		String id = request.getParameter("id");
		buildingModel model = service.getModel(id);
		request.setAttribute("model", model);
		ModelAndView mav = new ModelAndView("view/grid/chuzuwu_grid");
		return mav;
	}
	
	@RequestMapping(value = "/getTermpostListGrid")
	public @ResponseBody String getTermpostListGrid(HttpServletRequest request, HttpServletResponse response){
		String json = service.getModelList();
		return json;
	}
	
	@RequestMapping(value = "/getBuildingModel")
	public @ResponseBody String getBuildingModel(HttpServletRequest request, HttpServletResponse response){
		String id = request.getParameter("id");
		HashMap<String, Object> model = service.getBuildingModel(id);
		String json = JsonResultUtil.Success("", JsonUtil.ConvertObjectToJson(model));
		return json;
	}
	
	@RequestMapping(value = "/getCountDay")
	public @ResponseBody String getCountDay(HttpServletRequest request, HttpServletResponse response){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String date = sdf.format(new Date());
		HashMap<String, Object> parm = new HashMap<String, Object>();
		parm.put("start", date + " 00:00:00");
		parm.put("stop", date + " 23:59:59");
		String json = service.getCountDay(parm);
		return json;
	}
	
	@RequestMapping(value = "updateAttfileStutasApp")
	public @ResponseBody String updateAttfileStutasApp(HttpServletRequest request, HttpServletResponse response){
		HashMap<String, String> parm = RequestUnit.getHashMapParmS();
		
		service.updateAttfileStutas(parm);
		
		return JsonResultUtil.Success();
	}
}
